/**
 * =========================================
 *
 * Koa 使用 koa-bodyparser 获取post提交的数据
 *
 *      1. npm install --save koa-bodyparser
 *
 *      2. const bodyParser = require('koa-bodyparser');
 *
 *      3. app.use(bodyParser())
 *
 *      4. ctx.request.body;
 *
 * =========================================
 */
const Koa = require('koa');
const router = require('koa-router')();
const views = require('koa-views');
const bodyParser = require('koa-bodyparser');

const app = new Koa();

// 配置模板引擎
app.use(views('views', { extension: 'ejs' }));

// 配置koa-bodyparser
app.use(bodyParser());


router.get('/', async (ctx) => {

    await ctx.render('index');
});

router.post('/doAdd', async (ctx) => {

    // 获取表单提交的数据
    console.log(ctx.request.body);

    ctx.body = ctx.request.body;
});



app.use(router.routes());
app.use(router.allowedMethods());

app.listen(8088);
console.log('Server run http://localhost:8088/');